<?php
$_classArray = array(
	3 => '其它公告',
	1 => '招投标信息',
	2 => '废旧物资处理信息'
);
function getClass($keys){
	global $_classArray;
	foreach ($_classArray as $key => $value){
		if ($keys == $key) {
			return $value;
		}
	}
	return false;
}
function add( )
{
	global $_classArray;
				echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form action=\"Admin_Notice.php?Action=addsever\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\">\r\n  <tr>\r\n   <td width=\"15%\" align=\"right\">公告标题：</td>\r\n   <td width=\"75%\"><input name=\"noticetitle\" type=\"text\" size=\"47\" dataType=\"Require\" msg=\"请填写公告标题\"/></td>\r\n  </tr>\r\n<tr>\r\n   <td width=\"15%\" align=\"right\">公告分类：</td>\r\n   <td width=\"75%\"><select name=\"class\">";
				foreach ($_classArray as $key => $value){
					echo "<option value=\"$key\">$value</option>";
				}
				echo "</select></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">公告内容：</td>\r\n    <td>";
				                $oFCKeditor = new FCKeditor('noticecontent')  ;
                                $oFCKeditor->BasePath = 'module/fckeditor/' ;   
                                $oFCKeditor->ToolbarSet = 'Default' ;
                                $oFCKeditor->InstanceName = 'noticecontent' ;
                                $oFCKeditor->Width = '100%' ;
                                $oFCKeditor->Height = '400' ;
                                $oFCKeditor->Value  = $db->Record['content'];
                                $oFCKeditor->Create() ;
				echo "</td>\r\n  </tr>\r\n  <tr>\r\n    <td>&nbsp;</td>\r\n    <td><input type=\"submit\" name=\"Submit_add\" value=\"添加公告\" /></td>\r\n  </tr>\r\n</form>\r\n</table>\r\n";
}

function edit( )
{
	global $_classArray;
				global $db;
				$db->query( "select * from tun2_notice WHERE id=".$_GET['id'] );
				if ( $db->next_record( ) )
				{
								echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <form action=\"Admin_Notice.php?Action=editsever\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\">\r\n    <tr>\r\n      <td width=\"15%\" align=\"right\">公告标题：</td>\r\n      <td width=\"75%\">\r\n      <input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\" />\r\n      <input name=\"noticetitle\" type=\"text\" value=\"";
								echo $db->Record['title'];
								echo "\" size=\"47\" dataType=\"Require\" msg=\"请填写公告标题\"/></td>\r\n    </tr>\r\n<tr>\r\n   <td width=\"15%\" align=\"right\">公告分类：</td>\r\n   <td width=\"75%\"><select name=\"class\">";
								foreach ($_classArray as $key => $value){
									echo "<option value=\"$key\" ";
									if ($db->Record['class']==$key) {
										echo "selected=\"selected\"";
									}
									echo ">$value</option>";
								}
								echo "</select></td>\r\n  </tr>\r\n    <tr>\r\n      <td align=\"right\">公告内容：</td>\r\n      <td>";
								$oFCKeditor = new FCKeditor('noticecontent')  ;
                                $oFCKeditor->BasePath = 'module/fckeditor/' ;   
                                $oFCKeditor->ToolbarSet = 'Default' ;
                                $oFCKeditor->InstanceName = 'noticecontent' ;
                                $oFCKeditor->Width = '100%' ;
                                $oFCKeditor->Height = '400' ;
                                $oFCKeditor->Value  = $db->Record['content'];
                                $oFCKeditor->Create() ;
								echo "</td>\r\n    </tr>\r\n    <tr>\r\n      <td>&nbsp;</td>\r\n      <td><input type=\"submit\" name=\"Submit_edit\" value=\"修改公告\" /></td>\r\n    </tr>\r\n  </form>\r\n</table>\r\n";
				}
}

include( "inc/header.php" );
login_check( );
include("module/fckeditor/fckeditor.php") ;
echo "\r\n<body>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr>\r\n    <td><a href=\"Admin_Notice.php\">公告管理首页</a> ｜ <a href=\"Admin_Notice.php?Action=add\">添加新的公告</a></td>\r\n  </tr>\r\n</table>\r\n<br>\r\n";
switch ( $_GET['Action'] )
{
case "add" :
				add( );
				break;
case "addsever" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
					date_default_timezone_set( "Hongkong" );
				}
				@$GLOBALS['_POST'][noticetime] = date( "Y-m-d H-i-s" );
				$db->query( "INSERT INTO tun2_notice (title,content,time,class) \r\n\t\tVALUES ('".$_POST['noticetitle']."','{$_POST['noticecontent']}','{$_POST['noticetime']}','{$_POST['class']}')" );
				addlog( "添加公告", $_SESSION['user_name'] );
				admin_showerr( "<li>公告添加成功</li>", "Admin_Notice.php", 1 );
				break;
case "edit" :
				edit( );
				break;
case "editsever" :
				$db->query( "UPDATE tun2_notice SET title='".$_POST['noticetitle']."',\r\n\t\tcontent='{$_POST['noticecontent']}',\r\n\t\tclass='{$_POST['class']}' WHERE id={$_POST['id']}" );
				addlog( "修改公告", $_SESSION['user_name'] );
				admin_showerr( "<li>公告修改成功</li>", "Admin_Notice.php", 1 );
				break;
case "del" :
				$db->query( "DELETE FROM tun2_notice WHERE id=".$_GET['id'] );
				addlog( "删除公告", $_SESSION['user_name'] );
				admin_showerr( "<li>公告删除成功</li>", "Admin_Notice.php", 1 );
				break;
default :
				$db->query( "SELECT * FROM tun2_notice" );
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr>\r\n    <td width=\"5%\" align=\"center\"><strong>ID</strong></td>\r\n    <td align=\"center\"><strong>标题</strong></td>\r\n    <td align=\"center\"><strong>所属分类</strong></td>\r\n    <td width=\"18%\" align=\"center\"><strong>发布时间</strong></td>\r\n    <td width=\"15%\" align=\"center\"><strong>操作</strong></td>\r\n  </tr>\r\n";
				while ( $db->next_record( ) )
				{
								echo "<form action=\"Admin_Notice.php\" method=\"post\" name=\"form";
								echo $db->Record['id'];
								echo "\">\r\n  <tr>\r\n    <td width=\"4%\" align=\"center\">";
								echo $db->Record['id'];
								echo "</td>\r\n    <td>";
								echo $db->Record['title'];
								echo "</td>\r\n    <td align=\"center\">";
								echo getClass($db->Record['class']);
								echo "</td>\r\n   <td align=\"center\">";
								echo $db->Record['time'];
								echo "</td>\r\n    <td align=\"center\"><a href=\"Admin_Notice.php?Action=edit&id=";
								echo $db->Record['id'];
								echo "\">编辑</a> ｜\r\n    <a href=\"Admin_Notice.php?Action=del&id=";
								echo $db->Record['id'];
								echo "\" onClick=\"javascript:if(confirm('确定要删除吗？')){return true;}else{return false;}\">删除</a></td>\r\n  </tr>\r\n</form>\r\n";
				}
}
echo "</table>\r\n</body>\r\n</html>";